﻿#region << 文件说明 >>
/*----------------------------------------------------------------
 * 命名空间：Vampirewal.Core.WPF.Theme.CustomControl.MaskDialogGrid
 * 唯一标识：516adc43-0953-4111-b918-84f8a78bc651
 * 文件名：MaskDialogGrid
 * 
 * 创建者：杨程
 * 电子邮箱：235160615@qq.com
 * 创建时间：2023/11/14 11:01:37
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/
 #endregion << 文件说明 >>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Vampirewal.Core.WPF.Theme;

/// <summary>
/// 带遮罩的Dialog弹窗
/// </summary>
public partial class MaskDialogGrid: ContentControl
{
    static MaskDialogGrid()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(MaskDialogGrid), new FrameworkPropertyMetadata(typeof(MaskDialogGrid)));
    }

    public MaskDialogGrid()
    {
        //构造函数
    }

    private Border MaskBg { get; set; }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        MaskBg = this.Template.FindName("MaskBg", this) as Border;

        MaskBg.MouseLeftButtonDown += MaskBg_MouseLeftButtonDown;
    }

    /// <summary>
    /// 是否开启点击Mask区域关闭
    /// </summary>
    public bool IsOpenClickMaskClose { get; set; } = true;

    private void MaskBg_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        if (IsOpenClickMaskClose)
        {
            this.SetValue(IsShowDialogProperty, false);
        }

    }


    /// <summary>
    /// 是否显示弹窗
    /// </summary>
    public bool IsShowDialog
    {
        get { return (bool)GetValue(IsShowDialogProperty); }
        set { SetValue(IsShowDialogProperty, value); }
    }

    // Using a DependencyProperty as the backing store for IsShowDialog.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty IsShowDialogProperty =
        DependencyProperty.Register("IsShowDialog", typeof(bool), typeof(MaskDialogGrid), new PropertyMetadata(false));



    /// <summary>
    /// 遮罩的透明度
    /// </summary>
    public double MaskOpacity
    {
        get { return (double)GetValue(MaskOpacityProperty); }
        set { SetValue(MaskOpacityProperty, value); }
    }

    // Using a DependencyProperty as the backing store for MaskOpacity.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty MaskOpacityProperty =
        DependencyProperty.Register("MaskOpacity", typeof(double), typeof(MaskDialogGrid), new PropertyMetadata(0.5d));



    /// <summary>
    /// 弹窗背景色
    /// </summary>
    public Brush DialogBackground
    {
        get { return (Brush)GetValue(DialogBackgroundProperty); }
        set { SetValue(DialogBackgroundProperty, value); }
    }

    // Using a DependencyProperty as the backing store for MaskBackground.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty DialogBackgroundProperty =
        DependencyProperty.Register("DialogBackground", typeof(Brush), typeof(MaskDialogGrid), new PropertyMetadata(Brushes.White));


    /// <summary>
    /// 遮罩背景色
    /// </summary>
    public Brush MaskBackground
    {
        get { return (Brush)GetValue(MaskBackgroundProperty); }
        set { SetValue(MaskBackgroundProperty, value); }
    }

    // Using a DependencyProperty as the backing store for MaskBackground.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty MaskBackgroundProperty =
        DependencyProperty.Register("MaskBackground", typeof(Brush), typeof(MaskDialogGrid), new PropertyMetadata(Brushes.Gray));



    #region 弹窗内


    /// <summary>
    /// 标题
    /// </summary>
    public string Title
    {
        get { return (string)GetValue(TitleProperty); }
        set { SetValue(TitleProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Title.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty TitleProperty =
        DependencyProperty.Register("Title", typeof(string), typeof(MaskDialogGrid), new PropertyMetadata(""));



    /// <summary>
    /// 弹窗宽度
    /// </summary>
    public double DialogWidth
    {
        get { return (double)GetValue(DialogWidthProperty); }
        set { SetValue(DialogWidthProperty, value); }
    }

    // Using a DependencyProperty as the backing store for DialogWidth.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty DialogWidthProperty =
        DependencyProperty.Register("DialogWidth", typeof(double), typeof(MaskDialogGrid), new PropertyMetadata(300d));



    /// <summary>
    /// 弹窗高度
    /// </summary>
    public double DialogHeight
    {
        get { return (double)GetValue(DialogHeightProperty); }
        set { SetValue(DialogHeightProperty, value); }
    }

    // Using a DependencyProperty as the backing store for DialogHeight.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty DialogHeightProperty =
        DependencyProperty.Register("DialogHeight", typeof(double), typeof(MaskDialogGrid), new PropertyMetadata(400d));



    /// <summary>
    /// 弹窗内标题背景色
    /// </summary>
    public Brush TitleBackground
    {
        get { return (Brush)GetValue(TitleBackgroundProperty); }
        set { SetValue(TitleBackgroundProperty, value); }
    }

    // Using a DependencyProperty as the backing store for TitleBackground.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty TitleBackgroundProperty =
        DependencyProperty.Register("TitleBackground", typeof(Brush), typeof(MaskDialogGrid), new PropertyMetadata(Brushes.AliceBlue));



    /// <summary>
    /// 标题前景色
    /// </summary>
    public Brush TitleForeground
    {
        get { return (Brush)GetValue(TitleForegroundProperty); }
        set { SetValue(TitleForegroundProperty, value); }
    }

    // Using a DependencyProperty as the backing store for TitleForeground.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty TitleForegroundProperty =
        DependencyProperty.Register("TitleForeground", typeof(Brush), typeof(MaskDialogGrid), new PropertyMetadata(Brushes.White));


    #endregion
}